type Add<Lhs extends number, Rhs extends number> = Length<[...BuildArray<Lhs>, ...BuildArray<Rhs>]>;

type Result51 = Add<1, 2>;

type Subtract<Lhs extends number, Rhs extends number> = BuildArray<Lhs> extends [
  ...x: BuildArray<Rhs>,
  ...Rest: infer R,
]
  ? Length<R>
  : never;

type Repeat<N extends number, E> = IsEq<N, 1> extends true
  ? [E]
  : [E, ...Repeat<Subtract<N, 1>, E>];

type Result52 = Repeat<10, 2>;

type ReduceNumber<Acc extends number, Other extends number, I extends number> = Other extends 0
  ? I
  : ReduceNumber<Acc, Subtract<Other, 1>, Add<Acc, I>>;

type Multiply<Lhs extends number, Rhs extends number> = ReduceNumber<Lhs, Rhs, 0>;

type Result53 = Multiply<2, 3>;

type Multiply1<
  Lhs extends number,
  Rhs extends number,
  Result extends unknown[] = [],
> = Rhs extends 0
  ? Length<Result>
  : Multiply1<Lhs, Subtract<Rhs, 1>, [...BuildArray<Lhs>, ...Result]>;

type Result54 = Multiply1<4, 5>;

type Divide<Lhs extends number, Rhs extends number, Arr extends unknown[] = []> = Lhs extends 0
  ? Length<Arr>
  : Divide<Subtract<Lhs, Rhs>, Rhs, [unknown, ...Arr]>;

type Result55 = Divide<5, 2>;

type ArrayLen<T extends unknown[]> = T extends [unknown, ...infer R] ? Add<1, ArrayLen<R>> : 0;
type StrLen<T extends string> = T extends `${string}${infer Rest}` ? Add<1, StrLen<Rest>> : 0;

type StrLength<T extends string, Count extends unknown[] = []> = T extends `${string}${infer Rest}`
  ? StrLength<Rest, [...Count, unknown]>
  : Length<Count>;

type Result56 = StrLen<'abcdefg'>;
type Result57 = ArrayLen<[1, 2, 3, 4]>;
type Result58 = StrLength<'abcdefg'>;

type GT<Lhs extends number, Rhs extends number, Count extends unknown[] = []> = Lhs extends Rhs
  ? false
  : Length<Count> extends Rhs
  ? true
  : Length<Count> extends Lhs
  ? false
  : GT<Lhs, Rhs, [...Count, unknown]>;

type Result59 = GT<2, 1>;

type Fibonacci<N extends number, Prev1 extends number = 1, Prev2 extends number = 1> = N extends 1
  ? Prev1
  : Fibonacci<Subtract<N, 1>, Prev2, Add<Prev1, Prev2>>;

type Result60 = Fibonacci<8>;
